package com.link.base.base.questionnairesurvey.controller;

import com.link.base.base.questionnairesurvey.model.Topic;
import com.link.base.base.questionnairesurvey.service.TopicService;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.BasicServiceException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 刘鲁
 * @date 2018-07-04
 * @comments 问卷主题
 */
@Controller
@RequestMapping("/link/topic")
public class TopicController extends BasicController<Topic> {
    private static final Logger logger = LogManager.getLogger(TopicController.class);

    @Resource
    private TopicService topicService;

    @Override
    public BasicService<Topic> getBasicService() throws Exception {
        return topicService;
    }

    @RequestMapping({"/batchUpdateShowFlag"})
    @ResponseBody
    public Map<String, Object> batchUpdateShowFlag(@RequestBody List<Topic> list,
                                                   HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        HashMap result = new HashMap(4);
        try {
            topicService.batchUpdateShowFlag(list);
            result.put("success", true);
        } catch (BasicServiceException var8) {
            logger.error("TopicController捕获异常: ", var8);
            result.put("success", false);
            result.put("result", var8.getMessage());
            result.put("detailMessage", var8.getDetailMessage());
        } catch (Exception var9) {
            logger.error("TopicController捕获异常: ", var9);
            result.put("success", false);
            result.put("result", var9.getMessage());
        }
        return result;
    }

}
